package com.future.mayi.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.future.mayi.R;
import com.future.mayi.model.RecycleOrderModel;
import com.future.mayi.view.RecycleOrderGoodsItemView;
import com.future.mayi.view.xrecyclerview.XRecyclerView;

import butterknife.BindView;
import butterknife.ButterKnife;

public class RecycleAllOrderAdapter extends BaseRecyclerViewAdapter<RecycleOrderModel> {
    private int style;

    public RecycleAllOrderAdapter(Context context, XRecyclerView recyclerView, int style) {
        super(context, null, recyclerView);
        this.style = style;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ViewHolder(getView(parent, R.layout.layout_recycle_order_item));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, final int position) {
        ViewHolder holder = (ViewHolder) viewHolder;
        RecycleOrderModel model = getItem(position);

        if (mOnItemClickListener != null){
            viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mOnItemClickListener.OnItem(v, position);
                }
            });

            holder.tvEnter.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    mOnItemClickListener.OnItem(v, position);
                }
            });
        }



        setText(holder.tvOrderCode, (style == 1 ? "寄卖" : "回收") + "编号：" + model.getOrder_no());
        //订单状态 0-待报价 10-已报价 20-已寄件 30-出售中(寄卖专用) 40-已完成 90-已取消
        holder.tvEnter.setVisibility(View.GONE);
        switch (model.getStatus()) {
            // 0-待报价
            case 0:
                setText(holder.tvState, "待报价");
                break;
            // 10-已报价
            case 10:
                holder.tvEnter.setVisibility(View.VISIBLE);
                setText(holder.tvEnter, "填写寄件物流");
                setText(holder.tvState, "已报价");
                break;
            // 20-已寄件
            case 20:
                holder.tvEnter.setVisibility(View.VISIBLE);
                setText(holder.tvEnter, "查物流");
                setText(holder.tvState, "已寄件");
                break;
            // 30-出售中
            case 30:
                setText(holder.tvState, "寄卖中");
                break;
            // 40-已完成
            case 40:
                setText(holder.tvState, "已完成");
                break;
            // 90-已取消
            case 90:
                setText(holder.tvState, "已取消");
                break;
        }
        holder.recycleView.setGoods_item(model.getGoods_item());
    }

    class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.tv_order_code)
        TextView tvOrderCode;
        @BindView(R.id.tv_state)
        TextView tvState;
        @BindView(R.id.recycle_view)
        RecycleOrderGoodsItemView recycleView;
        @BindView(R.id.tv_enter)
        TextView tvEnter;

        public ViewHolder(View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
        }
    }


}
